import os

import requests
# uploadurl = ''
uploadurl = ''
saveurl = ''
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36',
    'Cookie':'JSESSIONID=ae02f9c2-9915-4ca0-b87c-37f369a97db8; James_cookie_sYQDUGqqzHtheme=custom'
}

file_dir = r'D:\Desktop\exceltest\部门'
all_files = os.listdir(file_dir)
xls_files = list(filter(lambda name: name.endswith('.xls'),all_files))
for file_name in xls_files:
    with open(rf'{file_dir}\{file_name}', 'rb') as xls:
        files ={}
        region = file_name.split('.')[0]
        region_name = region.split('--')[0]
        region_code = region.split('--')[1]
        param = {}
        param['url'] = ''
        param['filepath1'] = ''
        param['filename'] = file_name
        param['parent_name'] = '直属机关'
        param['parent_code'] = f'{region_code}O'
        param['region_name'] = region_name
        param['region_code'] = region_code
        param['organ_level'] = '3' if region_code.endswith('00') else '4'
        param['parent_type'] = 'region'
        param['type'] = '0'
        param['path_parent_code'] = ''
        files['file'] = xls
        print(param)
        response = requests.post(url=uploadurl, headers=headers, data=param, files=files)
        if response.status_code == 200 and response.json()['statusCode'] == 200:
            print(response.text)
            param['filepath1'] = response.json()['filePath']
            response = requests.post(url=saveurl, headers=headers, data=param)
            print(response.text)